﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
using System.Resources;

namespace spktNhom4DoAnCuoiKy
{
    public static class SessionExtension
    {
        public static string getLanguageCode(this HttpSessionState session)
        {
            if (session["LanguageCode"] != null)
            {
                return session["LanguageCode"].ToString();
            }
            return "vi-VN";
        }
        public static void setLanguageCode(this HttpSessionState session,string code)
        {
            session["LanguageCode"] =  code;
           
        }
        public static ResourceManager getResourceManager(this HttpSessionState session) {
            ResourceManager rm = new ResourceManager("Resources.String", System.Reflection.Assembly.Load("App_GlobalResources"));
            return rm;
        }
        public static PhienDauGia getCurrentAuctionSession(this HttpSessionState session) 
        {
            if (session["CurrentAuctionSession"] != null)
            {
                return (PhienDauGia)session["CurrentAuctionSession"];
            }
            else return null;
        }
        public static void setCurrentAuctionSession(this HttpSessionState session,PhienDauGia sd)
        {
            session["CurrentAuctionSession"] = sd;
            
        }
        public static aspnet_User getUserLogin(this HttpSessionState session)
        {
            if (session["CurrentUserLogin"] != null)
            {
                return (aspnet_User)session["CurrentUserLogin"];
            }
            else return null;
        }
        public static void setUserLogin(this HttpSessionState session, aspnet_User sd)
        {
            session["CurrentUserLogin"] = sd;

        }
        public static bool IsAuctionSessionChange(this HttpSessionState session)
        {
            if (session["IsAuctionSessionChange"] != null)
            {
                return (bool)session["IsAuctionSessionChange"];

            }
            session["IsAuctionSessionChange"] = false;
            return false;
        }
        public static void InformAuctionSessionChange(this HttpSessionState session)
        {
            
            session["IsAuctionSessionChange"] = true;
          
        }
        public static void InformReceivedChange(this HttpSessionState session)
        {

            session["IsAuctionSessionChange"] = false;

        }
        public static bool HasMessage(this HttpSessionState session)
        {
            if (session["HasMessages"]!=null)
            {
                return (bool)session["HasMessages"];
            }

            session["HasMessages"] = false;
            return false;
        }
        public static string getMessages(this HttpSessionState session)
        {
            if (session["Messages"] != null)
            {
                return session["Messages"].ToString();
            }
            return "";
        }
        public static string getRecipients(this HttpSessionState session)
        {
            if (session["Recipients"] != null)
            {
                return session["Recipients"].ToString();
            }
            return "";
        }
        public static void SendMessages(this HttpSessionState session,string messages,string username)
        {
            session["HasMessages"] = true;
            session["Messages"] = messages;
            session["Recipients"] = username;
        }
        public static void InformReicevedMessages(this HttpSessionState session)
        {
            session["HasMessages"] = false;
            return;
        }
    }
}